---
layout: "default"
title: "RawRepresentable"
description: "Swift documentation for 'RawRepresentable': A type that can be converted to an associated &quot;raw&quot; type, then
converted back to produce an instance equivalent to the original."
keywords: "RawRepresentable,protocol,swift,documentation,rawValue,RawValue"
root: "/v2.1"
---

<div class="intro-declaration"><code class="language-swift">protocol RawRepresentable</code></div>

<div class="discussion comment">
    <p>A type that can be converted to an associated &quot;raw&quot; type, then
converted back to produce an instance equivalent to the original.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>

<tr>
<th id="aliases">Associated Types</th>
<td>
<span id="aliasesmark"></span>
<div class="declaration">
<code class="language-swift">RawValue</code>
<div class="comment">
    <p>The &quot;raw&quot; type that can be used to represent all values of <code>Self</code>.</p>

<p>Every distinct value of <code>self</code> has a corresponding unique
value of <code>RawValue</code>, but <code>RawValue</code> may have representations
that do not correspond to an value of <code>Self</code>.</p>
</div>
</div>
</td>
</tr>


<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init-rawvalue_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-rawvalue_">init?(<wbr>rawValue:)</a> <span class="required">Required</span><div class="comment collapse" id="comment-init-rawvalue_"><div class="p">
    <p>Convert from a value of <code>RawValue</code>, yielding <code>nil</code> iff
<code>rawValue</code> does not correspond to a value of <code>Self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(rawValue: Self.RawValue)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-rawvalue_-self-rawvalue">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-rawvalue_-self-rawvalue">var rawValue: Self.RawValue</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-rawvalue_-self-rawvalue"><div class="p">
    <p>The corresponding value of the &quot;raw&quot; type.</p>

<p><code>Self(rawValue: self.rawValue)!</code> is equivalent to <code>self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var rawValue: Self.RawValue { get }</code>

    </div></div>
</div>





